var cities=["-请选择-","重庆","四川","贵州","浙江"];
var er=[
["请选择"],
["-请选择-","彭水","丰都","黔江","秀山"],
["-请选择-","达州","汶川","成都","阿坝"],
["-请选择-","桂林","贵阳","遵义","安顺"],
["-请选择-","宁波","杭州","温州","嘉兴"]
];
b1.innerHTML="<option>"+cities.join("</option><option>")+"</option>";
b1.onchange=function(){
    var i=this.selectedIndex;
b2.innerHTML="<option>"+er[i].join("</option><option>")+"</option>";
}
b1.onchange();


//购物车
var btns = document.getElementsByTagName("button");
for (var i = 0; i < btns.length; i++) {
    btns[i].onclick = function () {
        if (this.innerHTML == "+") {
            f2(1,this);
        } else {  
            f2(-1,this);
        }
    
        f1();
    }
}
f1();


function f2(num,btn){
    if(num==1){
        var span =btn.previousElementSibling;
    }else{
        var span = btn.nextElementSibling;
    }
    var spanV = parseInt(span.innerHTML) +num;
    if (spanV > 0) {
        span.innerHTML = spanV;
        var price = btn.parentNode.previousElementSibling.innerHTML;
        btn.parentNode.nextElementSibling.innerHTML = spanV * price;
    }

    
}
function f1(){
    var tbody=document.getElementsByTagName("tbody")[0],
trs=tbody.children;
for(i=0,sum=0;i<trs.length;i++){
    //                      最后一个儿子
    sum += parseInt(trs[i].lastElementChild.innerHTML);
}
    total.innerHTML=sum;

}
